home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / termScroll.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  21KB  |  961 lines

  1. /*
  2. **    termScroll.c
  3. **
  4. **    Support routines for optimized screen scrolling.
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* ScrollLineRectFill():
  13.      *
  14.      *    Fill a rectangular portion of the window raster with the help
  15.      *    of the scrolling information.
  16.      */
  17.  
  18. VOID __regargs
  19. ScrollLineRectFill(struct RastPort *RPort,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY)
  20. {
  21.     if(RPort -> BitMap -> Depth > 1)
  22.     {
  23.         if(MinX < MaxX)
  24.         {
  25.                 /* Is there anything on the screen at all? */
  26.  
  27.             if(ScrollLineFirst <= ScrollLineLast)
  28.             {
  29.                 if(UseMasking)
  30.                 {
  31.                     WORD    ScrollLineMask    = 0,
  32.                         ScrollLineLeft    = 32767,
  33.                         ScrollLineRight    = 0,
  34.                         Temp,
  35.                         i;
  36.  
  37.                         /* Determine screen colour mask. */
  38.  
  39.                     for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  40.                     {
  41.                         if(ScrollLines[i] . Width)
  42.                         {
  43.                             if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  44.                                 ScrollLineLeft = Temp;
  45.  
  46.                             if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  47.                                 ScrollLineRight = Temp;
  48.  
  49.                             ScrollLineMask |= ScrollLines[i] . ColourMask;
  50.                         }
  51.                     }
  52.  
  53.                         /* Wrap the bits. */
  54.  
  55.                     ScrollLineMask &= DepthMask;
  56.  
  57.                         /* Did we get a sensible colour? */
  58.  
  59.                     if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
  60.                     {
  61.                             /* Determine new left margin. */
  62.  
  63.                         if(ScrollLineLeft > MinX)
  64.                             MinX = ScrollLineLeft;
  65.  
  66.                             /* Determine new right margin. */
  67.  
  68.                         if(ScrollLineRight < MaxX)
  69.                             MaxX = ScrollLineRight;
  70.  
  71.                             /* Determine new top line margin. */
  72.  
  73.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  74.                             MinY = Temp;
  75.  
  76.                             /* Determine new bottom line margin. */
  77.  
  78.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  79.                             MaxY = Temp;
  80.  
  81.                             /* Set the colour mask. */
  82.  
  83.                         SetWrMsk(RPort,ScrollLineMask);
  84.  
  85.                             /* Add margin for italics or boldface. */
  86.  
  87.                         if(MaxX == ScrollLineRight)
  88.                             MaxX += FontRightExtend;
  89.                     }
  90.                 }
  91.                 else
  92.                 {
  93.                     WORD    ScrollLineLeft    = 32767,
  94.                         ScrollLineRight    = 0,
  95.                         Temp,
  96.                         i;
  97.  
  98.                         /* Determine screen colour mask. */
  99.  
  100.                     for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  101.                     {
  102.                         if(ScrollLines[i] . Width)
  103.                         {
  104.                             if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  105.                                 ScrollLineLeft = Temp;
  106.  
  107.                             if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  108.                                 ScrollLineRight = Temp;
  109.                         }
  110.                     }
  111.  
  112.                         /* Did we get a sensible colour? */
  113.  
  114.                     if(ScrollLineLeft <= ScrollLineRight)
  115.                     {
  116.                             /* Determine new left margin. */
  117.  
  118.                         if(ScrollLineLeft > MinX)
  119.                             MinX = ScrollLineLeft;
  120.  
  121.                             /* Determine new right margin. */
  122.  
  123.                         if(ScrollLineRight < MaxX)
  124.                             MaxX = ScrollLineRight;
  125.  
  126.                             /* Determine new top line margin. */
  127.  
  128.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  129.                             MinY = Temp;
  130.  
  131.                             /* Determine new bottom line margin. */
  132.  
  133.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  134.                             MaxY = Temp;
  135.  
  136.                             /* Add margin for italics or boldface. */
  137.  
  138.                         if(MaxX == ScrollLineRight)
  139.                             MaxX += FontRightExtend;
  140.                     }
  141.                 }
  142.             }
  143.         }
  144.     }
  145.  
  146.         /* And clear the raster. */
  147.  
  148.     if(MinX < MaxX && MinY < MaxY)
  149.         RectFill(RPort,WindowLeft + MinX,WindowTop + MinY,WindowLeft + MaxX,WindowTop + MaxY);
  150. }
  151.  
  152.     /* ScrollLineRaster():
  153.      *
  154.      *    Scroll the window raster with the help
  155.      *    of the scrolling information.
  156.      */
  157.  
  158. VOID __regargs
  159. ScrollLineRaster(struct RastPort *RPort,WORD DeltaX,WORD DeltaY,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY,BYTE Smooth)
  160. {
  161.     if(RPort -> BitMap -> Depth > 1)
  162.     {
  163.         if(MinX < MaxX)
  164.         {
  165.             if(UseMasking)
  166.             {
  167.                 WORD ScrollLineMask;
  168.  
  169.                     /* Are we to scroll a line in horizontal direction? If so, use the
  170.                      * colour mask of the current line.
  171.                      */
  172.  
  173.                 if(DeltaX)
  174.                 {
  175.                         /* Set the colour mask. */
  176.  
  177.                     if(ScrollLineMask = ScrollLines[CursorY] . ColourMask & DepthMask)
  178.                         SetWrMsk(RPort,ScrollLineMask);
  179.                 }
  180.                 else
  181.                 {
  182.                         /* Any data on screen worth scrolling? */
  183.  
  184.                     if(ScrollLineFirst <= ScrollLineLast)
  185.                     {
  186.                         WORD Temp,First,Last,SaveMinY = MinY / TextFontHeight,SaveMaxY = MaxY / TextFontHeight,ScrollLineLeft = 32767,ScrollLineRight = 0,i;
  187.  
  188.                             /* Reset colourmask. */
  189.  
  190.                         ScrollLineMask = 0;
  191.  
  192.                             /* Build both the colour mask and the margins. */
  193.  
  194.                         for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  195.                         {
  196.                             if(ScrollLines[i] . Width)
  197.                             {
  198.                                 if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  199.                                     ScrollLineLeft = Temp;
  200.  
  201.                                 if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  202.                                     ScrollLineRight = Temp;
  203.  
  204.                                 ScrollLineMask |= ScrollLines[i] . ColourMask;
  205.                             }
  206.                         }
  207.  
  208.                             /* Wrap the bits. */
  209.  
  210.                         ScrollLineMask &= DepthMask;
  211.  
  212.                             /* Sensible results? */
  213.  
  214.                         if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
  215.                         {
  216.                                 /* Determine new left margin. */
  217.  
  218.                             if(ScrollLineLeft > MinX)
  219.                                 MinX = ScrollLineLeft;
  220.  
  221.                                 /* Determine new right margin. */
  222.  
  223.                             if(ScrollLineRight < MaxX)
  224.                                 MaxX = ScrollLineRight;
  225.  
  226.                                 /* Scroll down or up? */
  227.  
  228.                             if(DeltaY < 0)
  229.                             {
  230.                                     /* So we are to scroll down, find the first
  231.                                      * blank line if any.
  232.                                      */
  233.  
  234.                                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  235.                                     MinY = Temp;
  236.  
  237.                                     /* Find the last blank lines if any. */
  238.  
  239.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - DeltaY - 1) < MaxY)
  240.                                     MaxY = Temp;
  241.  
  242.                                     /* Determine margins and the like... */
  243.  
  244.                                 Last    = (MaxY + 1) / TextFontHeight;
  245.                                 First    = Last - ((MaxY - MinY + TextFontHeight + DeltaY) / TextFontHeight);
  246.                                 Temp    = (-DeltaY) / TextFontHeight;
  247.  
  248.                                     /* Move the scroll line info up. */
  249.  
  250.                                 for(i = Last - 1 ; i >= First ; i--)
  251.                                     ScrollLines[i] = ScrollLines[i - Temp];
  252.  
  253.                                     /* Clear the remaining lines. */
  254.  
  255.                                 for(i = First - Temp ; i < First ; i++)
  256.                                 {
  257.                                     ScrollLines[i] . Left        = 32767;
  258.                                     ScrollLines[i] . Right        = 0;
  259.                                     ScrollLines[i] . ColourMask    = 0;
  260.                                     ScrollLines[i] . Width        = 0;
  261.                                 }
  262.  
  263.                                     /* Is the first line we were working
  264.                                      * on the first line of the whole display?
  265.                                      * If so, update the line marker.
  266.                                      */
  267.  
  268.                                 if(!SaveMinY)
  269.                                     ScrollLineFirst += Temp;
  270.  
  271.                                     /* Now take a look at the last line.
  272.                                      * If the last line we were working
  273.                                      * on is in fact the last line of the
  274.                                      * display, update the line marker.
  275.                                      */
  276.  
  277.                                 if(SaveMaxY == LastLine)
  278.                                 {
  279.                                     ScrollLineLast += Temp;
  280.  
  281.                                     if(ScrollLineLast > LastLine)
  282.                                         ScrollLineLast = LastLine;
  283.                                 }
  284.                             }
  285.                             else
  286.                             {
  287.                                     /* So we are to scroll up, find the last
  288.                                      * blank line if any.
  289.                                      */
  290.  
  291.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  292.                                     MaxY = Temp;
  293.  
  294.                                     /* Find the first blank lines if any. */
  295.  
  296.                                 if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  297.                                     MinY = Temp;
  298.  
  299.                                     /* Determine margins and the like... */
  300.  
  301.                                 First    = MinY / TextFontHeight;
  302.                                 Last    = ((MaxY - MinY + TextFontHeight - DeltaY) / TextFontHeight);
  303.                                 Temp    = DeltaY / TextFontHeight;
  304.  
  305.                                     /* Move the scroll line info down. */
  306.  
  307.                                 for(i = First ; i < First + Last ; i++)
  308.                                     ScrollLines[i] = ScrollLines[i + Temp];
  309.  
  310.                                     /* Clear the remaining lines. */
  311.  
  312.                                 for(i = First + Last ; i < First + Last + Temp ; i++)
  313.                                 {
  314.                                     ScrollLines[i] . Left        = 32767;
  315.                                     ScrollLines[i] . Right        = 0;
  316.                                     ScrollLines[i] . ColourMask    = 0;
  317.                                     ScrollLines[i] . Width        = 0;
  318.                                 }
  319.  
  320.                                     /* Decrease number of last line. */
  321.  
  322.                                 if(SaveMaxY == LastLine)
  323.                                 {
  324.                                     if(ScrollLineLast > Temp)
  325.                                         ScrollLineLast -= Temp;
  326.                                     else
  327.                                         ScrollLineLast = 0;
  328.                                 }
  329.  
  330.                                     /* Decrease number of first line. */
  331.  
  332.                                 if(!SaveMinY)
  333.                                 {
  334.                                     if(ScrollLineFirst > Temp)
  335.                                         ScrollLineFirst -= Temp;
  336.                                     else
  337.                                         ScrollLineFirst = 0;
  338.                                 }
  339.                             }
  340.  
  341.                                 /* Adapt possible changes in the lines for first and last line. */
  342.  
  343.                             while(ScrollLineFirst < RasterHeight)
  344.                             {
  345.                                 if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  346.                                     ScrollLineFirst++;
  347.                                 else
  348.                                     break;
  349.                             }
  350.  
  351.                             while(ScrollLineLast > 0)
  352.                             {
  353.                                 if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  354.                                     ScrollLineLast--;
  355.                                 else
  356.                                     break;
  357.                             }
  358.  
  359.                                 /* Set the colour mask. */
  360.  
  361.                             SetWrMsk(RPort,ScrollLineMask);
  362.  
  363.                                 /* Add margin for italics or boldface. */
  364.  
  365.                             if(MaxX == ScrollLineRight)
  366.                                 MaxX += FontRightExtend;
  367.                         }
  368.                     }
  369.                 }
  370.             }
  371.             else
  372.             {
  373.                     /* Are we to scroll a line in horizontal direction? If so, use the
  374.                      * colour mask of the current line.
  375.                      */
  376.  
  377.                 if(!DeltaX)
  378.                 {
  379.                         /* Any data on screen worth scrolling? */
  380.  
  381.                     if(ScrollLineFirst <= ScrollLineLast)
  382.                     {
  383.                         WORD Temp,First,Last,SaveMinY = MinY / TextFontHeight,SaveMaxY = MaxY / TextFontHeight,ScrollLineLeft = 32767,ScrollLineRight = 0,i;
  384.  
  385.                             /* Build both the colour mask and the margins. */
  386.  
  387.                         for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  388.                         {
  389.                             if(ScrollLines[i] . Width)
  390.                             {
  391.                                 if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  392.                                     ScrollLineLeft = Temp;
  393.  
  394.                                 if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  395.                                     ScrollLineRight = Temp;
  396.                             }
  397.                         }
  398.  
  399.                             /* Sensible results? */
  400.  
  401.                         if(ScrollLineLeft <= ScrollLineRight)
  402.                         {
  403.                                 /* Determine new left margin. */
  404.  
  405.                             if(ScrollLineLeft > MinX)
  406.                                 MinX = ScrollLineLeft;
  407.  
  408.                                 /* Determine new right margin. */
  409.  
  410.                             if(ScrollLineRight < MaxX)
  411.                                 MaxX = ScrollLineRight;
  412.  
  413.                                 /* Scroll down or up? */
  414.  
  415.                             if(DeltaY < 0)
  416.                             {
  417.                                     /* So we are to scroll down, find the first
  418.                                      * blank line if any.
  419.                                      */
  420.  
  421.                                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  422.                                     MinY = Temp;
  423.  
  424.                                     /* Find the last blank lines if any. */
  425.  
  426.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - DeltaY - 1) < MaxY)
  427.                                     MaxY = Temp;
  428.  
  429.                                     /* Determine margins and the like... */
  430.  
  431.                                 Last    = (MaxY + 1) / TextFontHeight;
  432.                                 First    = Last - ((MaxY - MinY + TextFontHeight + DeltaY) / TextFontHeight);
  433.                                 Temp    = (-DeltaY) / TextFontHeight;
  434.  
  435.                                     /* Move the scroll line info up. */
  436.  
  437.                                 for(i = Last - 1 ; i >= First ; i--)
  438.                                     ScrollLines[i] = ScrollLines[i - Temp];
  439.  
  440.                                     /* Clear the remaining lines. */
  441.  
  442.                                 for(i = First - Temp ; i < First ; i++)
  443.                                 {
  444.                                     ScrollLines[i] . Left        = 32767;
  445.                                     ScrollLines[i] . Right        = 0;
  446.                                     ScrollLines[i] . Width        = 0;
  447.                                 }
  448.  
  449.                                     /* Is the first line we were working
  450.                                      * on the first line of the whole display?
  451.                                      * If so, update the line marker.
  452.                                      */
  453.  
  454.                                 if(!SaveMinY)
  455.                                     ScrollLineFirst += Temp;
  456.  
  457.                                     /* Now take a look at the last line.
  458.                                      * If the last line we were working
  459.                                      * on is in fact the last line of the
  460.                                      * display, update the line marker.
  461.                                      */
  462.  
  463.                                 if(SaveMaxY == LastLine)
  464.                                 {
  465.                                     ScrollLineLast += Temp;
  466.  
  467.                                     if(ScrollLineLast > LastLine)
  468.                                         ScrollLineLast = LastLine;
  469.                                 }
  470.                             }
  471.                             else
  472.                             {
  473.                                     /* So we are to scroll up, find the last
  474.                                      * blank line if any.
  475.                                      */
  476.  
  477.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  478.                                     MaxY = Temp;
  479.  
  480.                                     /* Find the first blank lines if any. */
  481.  
  482.                                 if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  483.                                     MinY = Temp;
  484.  
  485.                                     /* Determine margins and the like... */
  486.  
  487.                                 First    = MinY / TextFontHeight;
  488.                                 Last    = ((MaxY - MinY + TextFontHeight - DeltaY) / TextFontHeight);
  489.                                 Temp    = DeltaY / TextFontHeight;
  490.  
  491.                                     /* Move the scroll line info down. */
  492.  
  493.                                 for(i = First ; i < First + Last ; i++)
  494.                                     ScrollLines[i] = ScrollLines[i + Temp];
  495.  
  496.                                     /* Clear the remaining lines. */
  497.  
  498.                                 for(i = First + Last ; i < First + Last + Temp ; i++)
  499.                                 {
  500.                                     ScrollLines[i] . Left        = 32767;
  501.                                     ScrollLines[i] . Right        = 0;
  502.                                     ScrollLines[i] . Width        = 0;
  503.                                 }
  504.  
  505.                                     /* Decrease number of last line. */
  506.  
  507.                                 if(SaveMaxY == LastLine)
  508.                                 {
  509.                                     if(ScrollLineLast > Temp)
  510.                                         ScrollLineLast -= Temp;
  511.                                     else
  512.                                         ScrollLineLast = 0;
  513.                                 }
  514.  
  515.                                     /* Decrease number of first line. */
  516.  
  517.                                 if(!SaveMinY)
  518.                                 {
  519.                                     if(ScrollLineFirst > Temp)
  520.                                         ScrollLineFirst -= Temp;
  521.                                     else
  522.                                         ScrollLineFirst = 0;
  523.                                 }
  524.                             }
  525.  
  526.                                 /* Adapt possible changes in the lines for first and last line. */
  527.  
  528.                             while(ScrollLineFirst < RasterHeight)
  529.                             {
  530.                                 if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  531.                                     ScrollLineFirst++;
  532.                                 else
  533.                                     break;
  534.                             }
  535.  
  536.                             while(ScrollLineLast > 0)
  537.                             {
  538.                                 if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  539.                                     ScrollLineLast--;
  540.                                 else
  541.                                     break;
  542.                             }
  543.  
  544.                                 /* Add margin for italics or boldface. */
  545.  
  546.                             if(MaxX == ScrollLineRight)
  547.                                 MaxX += FontRightExtend;
  548.                         }
  549.                     }
  550.                 }
  551.             }
  552.         }
  553.     }
  554.  
  555.         /* And scroll the raster. */
  556.  
  557.     if(MinX < MaxX && MinY < MaxY)
  558.     {
  559.         LONG OldPen;
  560.  
  561.         MinX += WindowLeft;
  562.         MaxX += WindowLeft;
  563.  
  564.         MinY += WindowTop;
  565.         MaxY += WindowTop;
  566.  
  567.             /* Non-standard background colour? */
  568.  
  569.         if((OldPen = ReadBPen(RPort)) != MappedPens[0][0])
  570.         {
  571.             SetBPen(RPort,MappedPens[0][0]);
  572.  
  573.             if(Smooth && DeltaY)
  574.             {
  575.                 WORD Lines = DeltaY / 2;
  576.  
  577.                 if(Lines > 0)
  578.                 {
  579.                     while(Lines--)
  580.                     {
  581.                         WaitTOF();
  582.  
  583.                         ScrollRaster(RPort,0,2,MinX,MinY,MaxX,MaxY);
  584.                     }
  585.                 }
  586.                 else
  587.                 {
  588.                     while(Lines++)
  589.                     {
  590.                         WaitTOF();
  591.  
  592.                         ScrollRaster(RPort,0,-2,MinX,MinY,MaxX,MaxY);
  593.                     }
  594.                 }
  595.             }
  596.             else
  597.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  598.  
  599.             SetBPen(RPort,OldPen);
  600.         }
  601.         else
  602.         {
  603.             if(Smooth && DeltaY)
  604.             {
  605.                 WORD Lines = DeltaY / 2;
  606.  
  607.                 if(Lines > 0)
  608.                 {
  609.                     while(Lines--)
  610.                     {
  611.                         WaitTOF();
  612.  
  613.                         ScrollRaster(RPort,0,2,MinX,MinY,MaxX,MaxY);
  614.                     }
  615.                 }
  616.                 else
  617.                 {
  618.                     while(Lines++)
  619.                     {
  620.                         WaitTOF();
  621.  
  622.                         ScrollRaster(RPort,0,-2,MinX,MinY,MaxX,MaxY);
  623.                     }
  624.                 }
  625.             }
  626.             else
  627.                 ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  628.         }
  629.     }
  630. }
  631.  
  632.     /* ScrollLineEraseScreen(BYTE Mode):
  633.      *
  634.      *    Erase a part of the screen.
  635.      */
  636.  
  637. VOID __regargs
  638. ScrollLineEraseScreen(BYTE Mode)
  639. {
  640.     if(RPort -> BitMap -> Depth > 1)
  641.     {
  642.         WORD i;
  643.  
  644.         switch(Mode)
  645.         {
  646.                 /* Erase from first line to current cursor line (inclusive). */
  647.  
  648.             case 1:    ScrollLineFirst = CursorY;
  649.  
  650.                     /* Reset the lines. */
  651.  
  652.                 for(i = 0 ; i < CursorY ; i++)
  653.                 {
  654.                     ScrollLines[i] . Left        = 32767;
  655.                     ScrollLines[i] . Right        = 0;
  656.                     ScrollLines[i] . ColourMask    = 0;
  657.                     ScrollLines[i] . Width        = 0;
  658.                 }
  659.  
  660.                 ScrollLines[CursorY] . Left = CursorX + 1;
  661.  
  662.                 if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
  663.                 {
  664.                     ScrollLines[CursorY] . Left    = 32767;
  665.                     ScrollLines[CursorY] . Right    = 0;
  666.                 }
  667.  
  668.                 break;
  669.  
  670.                 /* Erase entire screen. */
  671.  
  672.             case 2:    for(i = 0 ; i < RasterHeight ; i++)
  673.                 {
  674.                     ScrollLines[i] . Left        = 32767;
  675.                     ScrollLines[i] . Right        = 0;
  676.                     ScrollLines[i] . ColourMask    = 0;
  677.                     ScrollLines[i] . Width        = 0;
  678.                 }
  679.  
  680.                 ScrollLineFirst    = 32767;
  681.                 ScrollLineLast    = 0;
  682.  
  683.                 break;
  684.  
  685.                 /* Erase from current cursor position to end of screen. */
  686.  
  687.             default:for(i = CursorY + 1 ; i < RasterHeight ; i++)
  688.                 {
  689.                     ScrollLines[i] . Left        = 32767;
  690.                     ScrollLines[i] . Right        = 0;
  691.                     ScrollLines[i] . ColourMask    = 0;
  692.                     ScrollLines[i] . Width        = 0;
  693.                 }
  694.  
  695.                 if(CursorX)
  696.                 {
  697.                     ScrollLines[CursorY] . Right = CursorX;
  698.  
  699.                     if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
  700.                     {
  701.                         ScrollLines[CursorY] . Left    = 32767;
  702.                         ScrollLines[CursorY] . Right    = 0;
  703.                     }
  704.                 }
  705.                 else
  706.                 {
  707.                     ScrollLines[CursorY] . Left    = 32767;
  708.                     ScrollLines[CursorY] . Right    = 0;
  709.                 }
  710.  
  711.                     /* Cleared the entire screen? */
  712.  
  713.                 if(CursorY)
  714.                     ScrollLineLast = CursorY;
  715.                 else
  716.                 {
  717.                     ScrollLineFirst    = 32767;
  718.                     ScrollLineLast    = 0;
  719.                 }
  720.  
  721.                 break;
  722.         }
  723.  
  724.             /* Adapt possible changes in the lines for first and last line. */
  725.  
  726.         while(ScrollLineFirst < RasterHeight)
  727.         {
  728.             if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  729.                 ScrollLineFirst++;
  730.             else
  731.                 break;
  732.         }
  733.  
  734.         while(ScrollLineLast > 0)
  735.         {
  736.             if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  737.                 ScrollLineLast--;
  738.             else
  739.                 break;
  740.         }
  741.     }
  742. }
  743.  
  744.     /* ScrollLineEraseLine(BYTE Mode):
  745.      *
  746.      *    Erase parts of the current cursor line.
  747.      */
  748.  
  749. VOID __regargs
  750. ScrollLineEraseLine(BYTE Mode)
  751. {
  752.     if(RPort -> BitMap -> Depth > 1)
  753.     {
  754.         switch(Mode)
  755.         {
  756.                 /* Erase from left margin to current cursor position (inclusive). */
  757.  
  758.             case 1:    ScrollLines[CursorY] . Left = CursorX + 1;
  759.                 break;
  760.  
  761.                 /* Erase entire line. */
  762.  
  763.             case 2:    ScrollLines[CursorY] . Left    = 32767;
  764.                 ScrollLines[CursorY] . Right    = 0;
  765.  
  766.                 break;
  767.  
  768.                 /* Erase from current cursor position towards end of line. */
  769.  
  770.             default:if(CursorX)
  771.                     ScrollLines[CursorY] . Right = CursorX;
  772.                 else
  773.                 {
  774.                     ScrollLines[CursorY] . Left    = 32767;
  775.                     ScrollLines[CursorY] . Right    = 0;
  776.                 }
  777.  
  778.                 break;
  779.         }
  780.  
  781.             /* Adapt possible changes in the lines for first and last line. */
  782.  
  783.         while(ScrollLineFirst < RasterHeight)
  784.         {
  785.             if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  786.                 ScrollLineFirst++;
  787.             else
  788.                 break;
  789.         }
  790.  
  791.         while(ScrollLineLast > 0)
  792.         {
  793.             if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  794.                 ScrollLineLast--;
  795.             else
  796.                 break;
  797.         }
  798.     }
  799. }
  800.  
  801.     /* ScrollLineEraseCharacters(WORD Chars):
  802.      *
  803.      *    Erase a number of characters in the current cursor line.
  804.      */
  805.  
  806. VOID __regargs
  807. ScrollLineEraseCharacters(WORD Chars)
  808. {
  809.     if(RPort -> BitMap -> Depth > 1)
  810.     {
  811.             /* Any characters to erase? */
  812.  
  813.         if(ScrollLines[CursorY] . Right)
  814.             ScrollLines[CursorY] . Right -= Chars;
  815.     }
  816. }
  817.  
  818.     /* ScrollLineShiftChar(WORD Size):
  819.      *
  820.      *    Shift the characters following the current cursor position
  821.      *    Size characters to the right.
  822.      */
  823.  
  824. VOID __regargs
  825. ScrollLineShiftChar(WORD Size)
  826. {
  827.     if(RPort -> BitMap -> Depth > 1)
  828.     {
  829.             /* Any characters to scroll? */
  830.  
  831.         if(ScrollLines[CursorY] . Right > 0)
  832.             ScrollLines[CursorY] . Right += Size;
  833.     }
  834. }
  835.  
  836.     /* ScrollLinePutString(WORD Length):
  837.      *
  838.      *    Update the line info according to the length of a string
  839.      *    to be printed.
  840.      */
  841.  
  842. VOID __regargs
  843. ScrollLinePutString(WORD Length)
  844. {
  845.     if(RPort -> BitMap -> Depth > 1)
  846.     {
  847.         LONG Width;
  848.  
  849.             /* Which scale is the font we are currently using? */
  850.  
  851.         if(RasterAttr[CursorY] >= SCALE_ATTR_TOP2X)
  852.         {
  853.                 /* Valid length? */
  854.  
  855.             if(CursorX + Length >= RasterWidth / 2)
  856.                 Length = (RasterWidth / 2) - CursorX;
  857.  
  858.                 /* Double width. */
  859.  
  860.             Width = TextFontWidth * 2;
  861.         }
  862.         else
  863.         {
  864.             if(Config -> EmulationConfig -> FontScale == SCALE_HALF)
  865.             {
  866.                     /* Valid length? */
  867.  
  868.                 if(CursorX + Length >= RasterWidth * 2)
  869.                     Length = (RasterWidth * 2) - CursorX;
  870.  
  871.                     /* Half width. */
  872.  
  873.                 Width = TextFontWidth / 2;
  874.             }
  875.             else
  876.             {
  877.                     /* Valid length? */
  878.  
  879.                 if(CursorX + Length >= RasterWidth)
  880.                     Length = RasterWidth - CursorX;
  881.  
  882.                     /* Normal width. */
  883.  
  884.                 Width = TextFontWidth;
  885.             }
  886.         }
  887.  
  888.             /* Sensible value? */
  889.  
  890.         if(Length > 0)
  891.         {
  892.             if(UseMasking)
  893.             {
  894.                 struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
  895.  
  896.                     /* Update line colour mask. */
  897.  
  898.                 Alias -> ColourMask |= ReadAPen(RPort) | ReadBPen(RPort);
  899.  
  900.                     /* Update font scale. */
  901.  
  902.                 Alias -> Width = Width;
  903.  
  904.                     /* Set write mask (will affect Text() since it is called
  905.                      * after this routine has finished.
  906.                      */
  907.  
  908.                 SetWrMsk(RPort,Alias -> ColourMask);
  909.  
  910.                     /* Update right margin. */
  911.  
  912.                 if(CursorX < Alias -> Left)
  913.                     Alias -> Left = CursorX;
  914.  
  915.                     /* Update left margin. */
  916.  
  917.                 if(CursorX + Length > Alias -> Right)
  918.                     Alias -> Right = CursorX + Length;
  919.  
  920.                     /* Update topmost line. */
  921.  
  922.                 if(CursorY < ScrollLineFirst)
  923.                     ScrollLineFirst = CursorY;
  924.  
  925.                     /* Update bottommost line. */
  926.  
  927.                 if(CursorY > ScrollLineLast)
  928.                     ScrollLineLast = CursorY;
  929.             }
  930.             else
  931.             {
  932.                 struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
  933.  
  934.                     /* Update font scale. */
  935.  
  936.                 Alias -> Width = Width;
  937.  
  938.                     /* Update right margin. */
  939.  
  940.                 if(CursorX < Alias -> Left)
  941.                     Alias -> Left = CursorX;
  942.  
  943.                     /* Update left margin. */
  944.  
  945.                 if(CursorX + Length > Alias -> Right)
  946.                     Alias -> Right = CursorX + Length;
  947.  
  948.                     /* Update topmost line. */
  949.  
  950.                 if(CursorY < ScrollLineFirst)
  951.                     ScrollLineFirst = CursorY;
  952.  
  953.                     /* Update bottommost line. */
  954.  
  955.                 if(CursorY > ScrollLineLast)
  956.                     ScrollLineLast = CursorY;
  957.             }
  958.         }
  959.     }
  960. }
  961.